<template>
  <div class="_wz_operationProcess">
    <!--详情-->
    <hiddenDetails :selectData="selectData"></hiddenDetails>
    <div class="demo-drawer-footer" style="z-index: 99;">
      <Button style="margin-right: 8px" @click="$emit('closeFun', false)">取消</Button>
      <template v-if="selectData.riskInspectItemCheckState == -1">
        <Button type="primary" @click="formTitle = '隐患上报';operationProcessType = true;">隐患上报</Button>
      </template>
      <template v-else-if="selectData.riskInspectItemCheckState == 0 || selectData.riskInspectItemHandleState == -1">
        <template v-if="selectData.riskInspectItemHandleState == 0">
          <Button type="primary" @click="formData = JSON.parse(JSON.stringify(selectData));formOperation = true;">退回</Button>
        </template>
        <Button type="primary" @click="formTitle = '隐患核查';operationProcessType = true;">隐患核查</Button>
      </template>

      <template v-else-if="selectData.riskInspectItemHandleState == 0 || selectData.riskInspectItemReviewState == -1">
        <template v-if="selectData.riskInspectItemReviewState  == 0">
          <Button type="primary" @click="formData = JSON.parse(JSON.stringify(selectData));formOperation = true;">退回</Button>
        </template>
        <Button type="primary" @click="formTitle = '隐患整改';operationProcessType = true;">隐患整改</Button>
      </template>
      <template v-else-if="selectData.riskInspectItemReviewState == 0">
        <Button type="primary" @click="formTitle = '隐患验收';operationProcessType = true;">隐患验收</Button>
      </template>
    </div>



    <Drawer :title="formTitle" v-model="operationProcessType" width="820" :mask-closable="false" :draggable="true" :styles="formOperationStyles">
      <!--上报  hiddenPerilsReport-->
      <hiddenPerilsReport v-if="operationProcessType && selectData.riskInspectItemCheckState == -1" @closeFun="closeFun" :selectData="operationSelectData"></hiddenPerilsReport>
      <!--隐患核查  hiddenTroubleVerification-->
      <hiddenTroubleVerification v-else-if="operationProcessType && (selectData.riskInspectItemCheckState == 0 || selectData.riskInspectItemHandleState == -1)" @closeFun="closeFun" :selectData="operationSelectData"></hiddenTroubleVerification>
      <!--隐患整改  riskManagementOperation-->
      <riskManagementOperation v-else-if="operationProcessType && (selectData.riskInspectItemHandleState == 0 || selectData.riskInspectItemReviewState == -1)" @closeFun="closeFun" :selectData="operationSelectData"></riskManagementOperation>
      <!--隐患验收  riskAcceptanceOperation-->
      <riskAcceptanceOperation v-else-if="operationProcessType && selectData.riskInspectItemReviewState == 0" @closeFun="closeFun" :selectData="operationSelectData"></riskAcceptanceOperation>
    </Drawer>





    <Modal v-model="formOperation" title="退回描述" :mask-closable="false" :footer-hide="true" width="600">
      <div v-if="formOperation">
        <div style="padding: 10px 0 53px 0;">
          <Form ref="formAdd" :model="formData" label-position="right" :label-width="100" :rules="ruleValidate">
            <FormItem label="核查描述" prop="riskInspectItemCheckContext" v-if="selectData.riskInspectItemCheckState == 0 || selectData.riskInspectItemHandleState == -1">
              <i-input v-model="formData.riskInspectItemCheckContext" placeholder="请填写核查描述" type="textarea" :autosize="{minRows: 5,maxRows: 5}"/>
            </FormItem>

            <FormItem label="整改描述" prop="riskInspectItemHandleContext" v-else-if="selectData.riskInspectItemHandleState == 0 || selectData.riskInspectItemReviewState == -1">
              <i-input v-model="formData.riskInspectItemHandleContext" placeholder="请填写整改描述" type="textarea" :autosize="{minRows: 5,maxRows: 5}"/>
            </FormItem>

<!--            <FormItem label="验收描述" prop="riskInspectItemReviewContext" v-else-if="selectData.riskInspectItemReviewState == 0">-->
<!--              <i-input v-model="formData.riskInspectItemReviewContext" placeholder="请填写验收描述" type="textarea" :autosize="{minRows: 5,maxRows: 5}"/>-->
<!--            </FormItem>-->
          </Form>
        </div>
        <div class="demo-drawer-footer" style="z-index: 99;">
          <Button style="margin-right: 8px" @click="formOperation = false;">取消</Button>
          <Button type="primary" @click="addSubmit('formAdd')">提交</Button>
        </div>

        <Spin size="large" fix v-if="spinShow1"></Spin>
      </div>
    </Modal>



    <Spin size="large" fix v-if="spinShow"></Spin>

  </div>
</template>
<script>



import hiddenPerilsReport from "./hiddenPerilsReport";//隐患上报
import hiddenTroubleVerification from "./hiddenTroubleVerification";//隐患核查
import riskManagementOperation from "./riskManagementOperation";//隐患整改
import riskAcceptanceOperation from "./riskAcceptanceOperation";//隐患验收

import hiddenDetails from "./hiddenDetails";// hiddenDetails  隐患详情

export default {
  props: ['selectData'],//接收来自父组件的数据
  components: {
    hiddenPerilsReport,//隐患上报
    hiddenTroubleVerification,//隐患核查
    riskManagementOperation,//隐患整改
    riskAcceptanceOperation,//隐患验收
    hiddenDetails,//隐患详情
  },
  data() {
    return {
      operationSelectData:{},//详情
      formOperationStyles: {//表单左侧移出css
        height: 'calc(100% - 55px)',
        overflow: 'auto',
        paddingBottom: '53px',
        position: 'static'
      },
      operationProcessType:false,//任务
      formTitle:'',
      spinShow:false,
      spinShow1:false,

      formOperation:false,//退回
      formData:{},
      ruleValidate: {//正则
        riskInspectItemCheckContext: [
          {required: true, message: '请填写核查描述', trigger: 'blur'}
        ],
        riskInspectItemHandleContext: [
          {required: true, message: '请填写整改描述', trigger: 'blur'}
        ],
        riskInspectItemReviewContext: [
          {required: true, message: '请填写验收描述', trigger: 'blur'}
        ],
      },


    }
  },
  beforeCreate() {//beforeCreate创建前状态

  },
  created() {//created创建完毕状态

  },
  beforeMount() {//beforeMount挂载前状态   DOM 元素然后塞入页面的过程

  },
  mounted() {//mounted 挂载结束状态
    let that = this;
    that.operationSelectData = JSON.parse(JSON.stringify(that.selectData));

  },
  methods: {//执行的方法


    //提交
    addSubmit(name) {
      var that = this;
      that.$refs[name].validate((valid) => {
        if (valid) {//正则判断使用
          let data = that.formData;

          if(data.riskInspectItemCheckState == 0 || data.riskInspectItemHandleState == -1){//核查驳回
            data.riskInspectItemCheckState = -1
            data.riskInspectItemProcess = 2;
          }else if(data.riskInspectItemHandleState == 0 || data.riskInspectItemReviewState == -1){//整改驳回
            data.riskInspectItemHandleState = -1
            data.riskInspectItemProcess = 3;
          }
          // else if(data.riskInspectItemReviewState == 0){//验收驳回
          //   data.riskInspectItemReviewState = -1
          // }
          let formData = new FormData();
          for (let key in data) {
            formData.append(key, data[key]);
          }
          that.$Spin.show();
          that.axios.post(that.apiUrl.webApi + "/risk/inspect/riskInspectItemOperate", formData, {headers: {'Content-Type': "application/x-www-form-urlencoded"}}).then(res => {
            that.$Spin.hide();
            if (!!res) {
              that.$Message.success('保存成功');
              that.$emit('closeFun', true)
            }
          }).catch(err => {
            console.log('失败', err);
          })
        } else {
          this.$Message.error('请正确填写表单');
        }
      })
    },
    //添加修改触发后关闭刷新
    closeFun(data) {
      var that = this;
      if (data) {//添加修改 刷新表单
        that.$emit('closeFun', true)
      }
      that.operationProcessType = false;

    },
  },
  watch: {//监听

  },
  beforeUpdate() {//beforeUpdate 更新前状态

  },
  updated() {//updated 更新完成状态

  },
  beforeDestroy() {//beforeDestroy 销毁前状态

  },
  destroyed() {//destroyed 销毁完成状态

  }
}
</script>
<style lang="less">
._wz_operationProcess {

}
</style>
